package com.person.jc.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
import com.person.jc.common.Constants;
import com.person.jc.service.security.TsCodeService;
import com.person.jc.tag.SelectTagDao;
import com.person.jc.utils.JsonMapper;

public class CommonController extends Controller {
	
	public void getSelectOptions(){
		String sqlname = getPara("sqlname");
		String sqlparam = getPara("sqlparam");
		List<Record> list = new ArrayList<Record>();
		if("getCodeData".equals(sqlname)){
			list = TsCodeService.me.getKindCode(sqlparam);
        }else{
        	list =  SelectTagDao.me.getExecuteResult(sqlname, sqlparam);
        }
		List<Object> resultList = new ArrayList<Object>();
		if(list!=null && !list.isEmpty()){
			for (Record tempMap : list) {
                String key = String.valueOf(tempMap.get(Constants.defSelectKey));
                String value = String.valueOf(tempMap.get(Constants.defSelectText));
                Map<String, Object> map_ = new HashMap<String, Object>();
				map_.put("ID", key);
				map_.put("TEXT", value);
				resultList.add(map_);
            }
		}
		renderText(JsonMapper.nonDefaultMapper().toJson(resultList));
	}

}
